package com.zzstm.eduservice.controller.front;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zzstm.commonUtils.R;
import com.zzstm.eduservice.entity.EduCourse;
import com.zzstm.eduservice.entity.EduTeacher;
import com.zzstm.eduservice.service.EduCourseService;
import com.zzstm.eduservice.service.EduTeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/eduservice/teacherfront")
@CrossOrigin
public class TeacherFrontController {

    @Autowired
    private EduTeacherService teacherService;

    @Autowired
    private EduCourseService courseService;

    //前台分页查询讲师
    @GetMapping("/getTeacherFrontList/{pageNum}/{pageSize}")
    public R getTeacherFrontList(@PathVariable long pageSize,@PathVariable long pageNum){
        Page<EduTeacher> page = new Page<>(pageNum,pageSize);
        Map<String,Object> map = teacherService.getTeacherFrontList(page);
        return R.ok().data(map);
    }

    //根据id获取讲师详情
    @GetMapping("/getTeacherInfo/{id}")
    public R getTeacherInfo(@PathVariable String id){
        //基本信息
        EduTeacher teacher = teacherService.getById(id);
        //所讲课程
        QueryWrapper<EduCourse> wrapper = new QueryWrapper<>();
        wrapper.eq("teacher_id",id);
        List<EduCourse> courseList = courseService.list(wrapper);
        return R.ok().data("teacher",teacher).data("courseList",courseList);
    }

}
